package DoublePointer;

import java.util.Scanner;

public class twoSum {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int [] numbers = {2, 7, 11, 15};
        int target = 9;
        twoSum twoSum = new twoSum();
        int[] res = twoSum.twoSum(numbers, target);
        System.out.println(res[0] + res[1]);
    }

    public int[] twoSum(int[] numbers, int target) {
        int length = numbers.length;
        int l = 0;
        int r = length - 1;
        while (l < r) {
            int sum = numbers[l] + numbers[r];
            if (sum == target) {
                return new int[]{l + 1, r + 1};
            } else if (sum > target) {
                r--;
            } else {
                l++;
            }
        }
        return null;
    }
}
